-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add excluded_content_types parameter to GZipMiddleware
#3091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the ability to customize which content types should be excluded from gzip compression in GZipMiddleware. It introduces two new keyword-only parameters: excluded_content_types to completely replace the default exclusions, and additional_excluded_content_types to add more exclusions while keeping the defaults. Additionally, it expands the default excluded content types to include already-compressed formats.
Changes:
- Added
excluded_content_typesandadditional_excluded_content_typesparameters toGZipMiddleware - Extended DEFAULT_EXCLUDED_CONTENT_TYPES to include application/zip, application/gzip, and application/x-gzip
- Propagated the excluded_content_types parameter through IdentityResponder and GZipResponder
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| excluded_content_types: tuple[str, ...] = DEFAULT_EXCLUDED_CONTENT_TYPES, | ||
| additional_excluded_content_types: tuple[str, ...] = (), |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new excluded_content_types and additional_excluded_content_types parameters lack test coverage. Consider adding tests that verify:
- Custom content types can be excluded from compression using
excluded_content_types - Additional content types can be excluded using
additional_excluded_content_types - The default excluded content types (application/zip, application/gzip, application/x-gzip) are properly excluded from compression
| excluded_content_types: tuple[str, ...] = DEFAULT_EXCLUDED_CONTENT_TYPES, | ||
| additional_excluded_content_types: tuple[str, ...] = (), |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation in docs/middleware.md should be updated to describe the new excluded_content_types and additional_excluded_content_types parameters. The current documentation at lines 240-244 mentions the default exclusion behavior but doesn't document that these can now be customized.
| DEFAULT_EXCLUDED_CONTENT_TYPES = ( | ||
| "text/event-stream", | ||
| "application/zip", | ||
| "application/gzip", | ||
| "application/x-gzip", | ||
| ) |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding new content types to DEFAULT_EXCLUDED_CONTENT_TYPES is a breaking change. While it's sensible to exclude already-compressed formats (application/zip, application/gzip, application/x-gzip), this changes the default behavior for existing users. Consider documenting this as a breaking change in the release notes and ensuring it's mentioned in the PR description or migration guide.
No description provided.